﻿/*----------------------------------------------------------------
//Copyright (C) 2012 赵国伟
//文件功能描述：商品管理客户端脚本
//创建人：赵国伟
//生成时间：2012-04-08 00:37:32
//----------------------------------------------------------------*/
var AjaxServerUrl = "/Manage/AS/GoodsCommon.aspx";
var ModelOfGoods;
var ModelOfPriceRule;
var ModelOfOnSale; //售卖规格对象；
var ModelOfGoodsPicture;
var ModelOfIDNameObj;
var GoodsID = 0;
var SelectOptionOfCategory = ""; //商品类别选项；
var SelectOptionOfPackUnit = ""; //商品包装类型选项；
var SelectOptionOfGoodsUnit = ""; //商品单位选项；
var SelectOptionOfSaleStatus = ""; //商品销售状态选项；
var CheckOptionOfCommend = ""; //商品推荐选项；
var SelectOptionOfPlace = ""; //商品产地选项；
var SelectOptionOfSpecialArea = ""; //商品所属专区选项。
var SWFUploader = null; //上传控件；(SwfUpload)
var SessionID = "";
var RulesTable = "tableOfPriceRules";
var RulesTableRow = "trMorePrice";
var CurRowOfRules = 0;

var OnSalesTable = "tableOfOnSales";
var OnSalesTableRow = "trMoreOnSales";
var CurRowOfOnSales = 0;
var UploadPic = new Array();
var ctrlOfSelectGoods; //商品选择控件。

///初始化
function Init() {
    GoodsID = 0;
    CurRowOfRules = 0;
    CurRowOfOnSales = 0;
    UploadPic = new Array();
}

///执行商品搜索；
function GoToSearch() {
    var url = "GoodsManage.aspx?";
    url += "keyWords=" + escape($("#txtKeyWords").val().trim());
    url += "&TCategoryID=" + $("#ddlCategoryOfSearch").val();
    url += "&BrandID=" + $("#ddlBrandOfSearch").val();
    url += "&GoodsPlaceID=" + $("#ddlPlaceOfSearch").val();
    url += "&SaleStatus=" + escape($("#ddlSaleStatusOfSearch").val());
    url += "&Status=" + escape($("#ddlStatusOfSearch").val());
    location.href = url;
}

//执行删除
function Delete(id) {
    if (!confirm("系统提示：您确定要删除该条商品信息？"))
        return;
    AjaxGet(AjaxServerUrl + "?Action=DeleteGoods&GoodsID=" + id);
}

///检查表单；
function CheckForm() {
    if ($("#ddlCategory").val() == "") {
        alert("系统提示：请选择商品类别！");
        $("#ddlCategory").focus();
        return false;
    }
    if ($("#ddlBrand").val() == "") {
        alert("系统提示：请选择品牌！");
        $("#ddlBrand").focus();
        return false;
    }
    if ($("#txtGoodsName").val() == "") {
        alert("系统提示：请输入商品名称！");
        $("#txtGoodsName").focus();
        return false;
    }
    if ($("#txtWeight").val() == "") {
        alert("系统提示：请输入商品重量！");
        $("#txtWeight").focus();
        return false;
    }
    if (!IsRate($("#txtWeight").val())) {
        alert("系统提示：商品重量填写错误！");
        $("#txtWeight").focus();
        return false;
    }
    if ($("#ddlGoodsPlace").val() == "") {
        alert("系统提示：请选择商品产地！");
        $("#ddlGoodsPlace").focus();
        return false;
    }
    if ($("#ddlSpecialArea").val() == "") {
        alert("系统提示：请选择专区！");
        $("#ddlSpecialArea").focus();
        return false;
    }
    if ($("#ddlPackUnit").val() == "") {
        alert("系统提示：请选择包装类型！");
        $("#ddlPackUnit").focus();
        return false;
    }
    if ($("#ddlGoodsUnit").val() == "") {
        alert("系统提示：请选择商品单位！");
        $("#ddlGoodsUnit").focus();
        return false;
    }
    if ($("#txtMarketPrice").val() == "") {
        alert("系统提示：请输入市场价格！");
        $("#txtMarketPrice").focus();
        return false;
    }
    if (!isMoney($("#txtMarketPrice").val())) {
        alert("系统提示：市场价格输入错误！");
        $("#txtMarketPrice").focus();
        return false;
    }
    if ($("#txtShelflifeDays").val() == "") {
        alert("系统提示：请输入保质期！");
        $("#txtShelflifeDays").focus();
        return false;
    }
    if (!IsNumber($("#txtShelflifeDays").val())) {
        alert("系统提示：保质期必须为数字！");
        $("#txtShelflifeDays").focus();
        return false;
    }
    if ($("#txtSalePrice").val() == "") {
        alert("系统提示：请输入销售价格！");
        $("#txtSalePrice").focus();
        return false;
    }
    if (!isMoney($("#txtSalePrice").val())) {
        alert("系统提示：销售价格输入错误！");
        $("#txtSalePrice").focus();
        return false;
    }
    //对更多价格设置的验证；//各种价格设置必须大于等于0；
    if (CurRowOfRules > 0) {
        for (var i = 0; i < CurRowOfRules; ++i) {
            if ($("#txtMinQuantityOf" + i) != null ) {
                //判断起购数量必须大于1；
                if (!IsNumber($("#txtMinQuantityOf" + i).val())) {
                    alert("系统提示：第" + (i + 1) + "条价格规则的起购数量必须为数字！");
                    $("#txtMinQuantityOf" + i).focus();
                    return false;
                }
                if (parseInt($("#txtMinQuantityOf" + i).val()) <= 1) {
                    alert("系统提示：第" + (i + 1) + "条价格规则的起购数量必须大于1");
                    $("#txtMinQuantityOf" + i).focus();
                    return false;
                }
                if (!isMoney($("#txtPriceOf" + i).val())) {
                    alert("系统提示：第" + (i + 1) + "条价格规则的单价输入错误！");
                    $("#txtPriceOf" + i).focus();
                    return false;
                }
            }
        }
    }

    //对更多规格售卖的验证；
    if (CurRowOfOnSales > 0) {
        for (var i = 0; i < CurRowOfOnSales; ++i) {
            if ($("#ddlPackUnitOf" + i) != null) {
                //判断起购数量必须大于1；
                if ($("#ddlPackUnitOf" + i).val() == $("#ddlPackUnit").val()) {
                    alert("系统提示：第" + (i + 1) + "条售卖规格中的包装规格重复！");
                    $("#ddlPackUnitOf" + i).focus();
                    return false;
                }
                if (!isMoney($("#txtSalePriceOf" + i).val())) {
                    alert("系统提示：第" + (i + 1) + "条售卖规格的单价输入错误！");
                    $("#txtSalePriceOf" + i).focus();
                    return false;
                }
            }
        }
    }

    if ($("#chkIsRush").attr("checked")) {
        if (!isMoney($("#txtRushPrice").val())) {
            alert("系统提示：抢购价输入错误！");
            $("#txtRushPrice").focus();
            return false;
        }
        if (parseFloat($("#txtRushPrice").val())<=0) {
            alert("系统提示：抢购价必须大于0！");
            $("#txtRushPrice").focus();
            return false;
        }
        if ($("#txtRushMaxQuantity").val() == "") {
            alert("系统提示：请输入限购数量！");
            $("#txtRushMaxQuantity").focus();
            return false;
        }
        if (!IsNumber($("#txtRushMaxQuantity").val())) {
            alert("系统提示：限购数量必须为数字！");
            $("#txtRushMaxQuantity").focus();
            return false;
        }
        if (parseInt($("#txtRushMaxQuantity").val())<=0) {
            alert("系统提示：限购数量必须大于0！");
            $("#txtRushMaxQuantity").focus();
            return false;
        }
    }



    if (!IsNumber($("#txtGiveScores").val())) {
        alert("系统提示：赠送积分必须为数字！");
        $("#txtGiveScores").focus();
        return false;
    }

    if (UploadPic == null || UploadPic.length <= 0) {
        alert("系统提示：请上传商品图片！");
        return false;
    }

    if (!IsNumber($("#txtOrderValue").val())) {
        alert("系统提示：排序值必须为数字！");
        $("#txtOrderValue").focus();
        return false;
    }
    return true;
}

//保存；
function Save(IsStillSaveNew) {
    $("#btnSave").attr("disabled", true);
    if (!CheckForm()) {
        $("#btnSave").attr("disabled", false);
        return;
    }
    if (IsStillSaveNew == undefined || IsStillSaveNew == null || IsStillSaveNew == "")
        IsStillSaveNew = false;
    var data = clone(ModelOfGoods);
    if (IsStillSaveNew)
        data.BaseInfo._goodsid = 0;
    else
        data.BaseInfo._goodsid = GoodsID;
    data.BaseInfo._categoryid = $("#ddlCategory").val();
    data.BaseInfo._brandid = $("#ddlBrand").val();
    data.BaseInfo._packunitid = $("#ddlPackUnit").val();
    data.BaseInfo._goodsunitid = $("#ddlGoodsUnit").val();
    data.BaseInfo._goodsname = $("#txtGoodsName").val();
    data.BaseInfo._isgroup = $("#chkIsGroup").attr("checked");
    data.BaseInfo._weight = $("#txtWeight").val();
    data.BaseInfo._goodsplaceid = $("#ddlGoodsPlace").val();
    data.BaseInfo._specialareaid = $("#ddlSpecialArea").val(); 
    data.BaseInfo._shelflifedays = $("#txtShelflifeDays").val();
    data.BaseInfo._marketprice = $("#txtMarketPrice").val();
    data.BaseInfo._saleprice = $("#txtSalePrice").val();

    data.BaseInfo._isrush = $("#chkIsRush").attr("checked");
    if (data.BaseInfo._isrush) {
        data.BaseInfo._rushprice = $("#txtRushPrice").val();
        data.BaseInfo._rushmaxquantity = $("#txtRushMaxQuantity").val();
    }

    data.BaseInfo._promotions = $("#txtPromotions").val();
    data.BaseInfo._givescores = $("#txtGiveScores").val();
    data.BaseInfo._package = $("#txtPackage").val();
    data.BaseInfo._afterservice = $("#txtAfterService").val();
    data.BaseInfo._barcode = $("#txtBarcode").val();
    data.BaseInfo._ordervalue = $("#txtOrderValue").val();
    data.BaseInfo._salestatus = $("#ddlSaleStatus").val();
    data.BaseInfo._status = $("#ddlStatus").val();
    data.BaseInfo._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
    data.BaseInfo._lastmodifydate = "/Date(" + CurrentDateStringToUTC() + ")/";

    //更多价格的获取；
    if (CurRowOfRules > 0) {
        data.PriceRules = new Array();
        for (var i = 0; i < CurRowOfRules; ++i) {
            if ($("#txtMinQuantityOf" + i) != null) {
                var priceRule = clone(ModelOfPriceRule);
                priceRule._goodsid = GoodsID;
                priceRule._minquantity = $("#txtMinQuantityOf" + i).val();
                priceRule._price = $("#txtPriceOf" + i).val();
                priceRule._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
                data.PriceRules.push(priceRule);
            }
        }
    }

    //更多售卖规格的获取；

    data.OnSales = new Array();
    var onSale = clone(ModelOfOnSale);
    onSale.OnSale._goodsid = GoodsID;
    onSale.OnSale._packunitid = $("#ddlPackUnit").val();
    onSale.OnSale._price = $("#txtSalePrice").val();
    onSale.OnSale._ismajor = true;
    data.OnSales.push(onSale);
    if (CurRowOfOnSales > 0) {
        for (var i = 0; i < CurRowOfOnSales; ++i) {
            if ($("#ddlPackUnitOf" + i) != null) {
                var onSale = clone(ModelOfOnSale);
                onSale.OnSale._goodsid = GoodsID;
                onSale.OnSale._packunitid = $("#ddlPackUnitOf" + i).val();
                onSale.OnSale._saleprice = $("#txtSalePriceOf" + i).val();
                onSale.OnSale._ismajor = false;
                data.OnSales.push(onSale);
            }
        }
    }

    //商品图片的获取；
    data.Pictures = UploadPic;


    //对商品推荐信息的获取；
    var commendCategoryIds = GetCheckObjectValuesToArray("chkCommend");
    if (commendCategoryIds != null && commendCategoryIds.length > 0) {
        data.GoodsCommends = new Array();
        for (var i = 0; i < commendCategoryIds.length; ++i) {
            var com = clone(ModelOfIDNameObj);
            com._id = commendCategoryIds[i];
            data.GoodsCommends.push(com);
        }
    }
    //商品的最佳组合；
    data.Packs = ctrlOfSelectGoods.SelectValueEx();
    var url = AjaxServerUrl + "?Action=SaveGoods";
    var postData = "jsonData=" + JSON.stringify(eval(data));
    postData += "&Description=" + escape(GetEditorHTMLContents("txtDescription"));
    AjaxPostEx(url, "btnSave", postData);  //更新数据；
    $("#btnSave").attr("disabled", false);
}

//绑定商品信息到录入表单中；
function BindGoodsToForm() {
    var url = AjaxServerUrl + "?action=GetGoods&GoodsID=" + GoodsID + "&tttt=" + Math.random();
    $.ajax(
    {
        type: "Get",
        url: url,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                $("#ddlCategory").val(data.BaseInfo._categoryid);
                if ($("#ddlCategory").val() == null || $("#ddlCategory").val() == "") {
                    $("#ddlCategory").append("<option value=\"" + data.BaseInfo._categoryid + "\" selected  style=\"background-color:#FF0000;\">" + data.CategoryName + "(已删除)</option>");
                }
                GetBrands(data.BaseInfo._categoryid, "ddlBrand", data.BaseInfo._brandid, function () {
                    if ($("#ddlBrand").val() == null || $("#ddlBrand").val() == "") {
                        $("#ddlBrand").append("<option value=\"" + data.BaseInfo._brandid + "\" selected  style=\"background-color:#FF0000;\">" + data.BrandName + "(已删除)</option>");
                    }
                })


                $("#ddlPackUnit").val(data.BaseInfo._packunitid);
                if ($("#ddlPackUnit").val() == null || $("#ddlPackUnit").val() == "") {
                    $("#ddlPackUnit").append("<option value=\"" + data.BaseInfo._packunitid + "\" selected  style=\"background-color:#FF0000;\">" + data.PackUnit + "(已删除)</option>");
                }
                $("#ddlGoodsUnit").val(data.BaseInfo._goodsunitid);
                if ($("#ddlGoodsUnit").val() == null || $("#ddlGoodsUnit").val() == "") {
                    $("#ddlGoodsUnit").append("<option value=\"" + data.BaseInfo._goodsunitid + "\" selected  style=\"background-color:#FF0000;\">" + data.GoodsUnit + "(已删除)</option>");
                }

                $("#txtGoodsName").val(data.BaseInfo._goodsname);
                $("#chkIsGroup").attr("checked", data.BaseInfo._isgroup);
                $("#txtWeight").val(data.BaseInfo._weight);
                $("#ddlGoodsPlace").val(data.BaseInfo._goodsplaceid);
                $("#ddlSpecialArea").val(data.BaseInfo._specialareaid);
                $("#txtShelflifeDays").val(data.BaseInfo._shelflifedays);
                $("#txtMarketPrice").val(data.BaseInfo._marketprice);
                $("#txtSalePrice").val(data.BaseInfo._saleprice);
                $("#chkIsRush").attr("checked", data.BaseInfo._isrush);
                $("#txtRushPrice").val(data.BaseInfo._rushprice);
                $("#txtRushMaxQuantity").val(data.BaseInfo._rushmaxquantity);
                $("#txtPromotions").val(data.BaseInfo._promotions);
                $("#txtGiveScores").val(data.BaseInfo._givescores);
                $("#txtPackage").val(data.BaseInfo._package);
                $("#txtAfterService").val(data.BaseInfo._afterservice);
                $("#txtBarcode").val(data.BaseInfo._barcode);
                $("#txtOrderValue").val(data.BaseInfo._ordervalue);
                $("#ddlSaleStatus").val(data.BaseInfo._salestatus);
                $("#ddlStatus").val(data.BaseInfo._status);
                $("#txtDescription").val(data.BaseInfo._description);

                //对更多价格的设置；
                if (data.PriceRules != null) {
                    for (var i = 0; i < data.PriceRules.length; ++i) {
                        AddPriceRule();
                        $("#txtMinQuantityOf" + i).val(data.PriceRules[i]._minquantity);
                        $("#txtPriceOf" + i).val(data.PriceRules[i]._price);
                    }
                }

                //对更多售卖规格的设置；
                if (data.OnSales != null) {
                    for (var i = 0; i < data.OnSales.length; ++i) {
                        if (!data.OnSales[i].OnSale._ismajor) {
                            AddOnSale();
                            $("#ddlPackUnitOf" + i).val(data.OnSales[i].OnSale._packunitid);
                            $("#txtSalePriceOf" + i).val(data.OnSales[i].OnSale._saleprice);
                        }
                    }
                }

                //对图片的输出设置；
                if (data.Pictures != null) {
                    UploadPic = data.Pictures;
                    for (var i = 0; i < UploadPic.length; ++i) {
                        UploadPic[i]._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
                    }
                    OutGoodsPic();
                }

                //对商品推荐的设置；
                if (data.GoodsCommends != null) {
                    var ids = new Array();
                    for (var i = 0; i < data.GoodsCommends.length; ++i) {
                        ids.push(data.GoodsCommends[i]._id);
                    }
                    SetCheckObjectDefaultValue("chkCommend", ids.join(","));
                }
                //对商品组合的设置；
                ctrlOfSelectGoods.SetDefaultValue(data.Packs);
            }
        }
    });
}

///添加界面；
function Add() {
    Init();
    GetPopupDiv(700, 800, "#e2e2e2", "添加商品", GetHtmlForm());
    SWFUploader = CreateSwfUploadObject("/Manage/AS/AjaxUpload.aspx?action=UploadFiles", SessionID, "*.jpg;*.gif;*.png", "图片文件", "spUploadBtn", "divGoodsPic");
    GetEditor("txtDescription", "98%");
    ctrlOfSelectGoods = new SelectGoods("btnSelGoods", "Muti", "spPacks", "");
}

//编辑界面；
function Edit(id) {
    Init();
    GoodsID = id;
    GetPopupDiv(700, 800, "#e2e2e2", "编辑商品", GetHtmlForm());
    SWFUploader = CreateSwfUploadObject("/Manage/AS/AjaxUpload.aspx?action=UploadFiles", SessionID, "*.jpg;*.gif;*.png", "图片文件", "spUploadBtn", "divGoodsPic");
    GetEditor("txtDescription", "98%");
    ctrlOfSelectGoods = new SelectGoods("btnSelGoods", "Muti", "spPacks", "");
    BindGoodsToForm();
}


function GetBrands(categoryId,objControl,defaultValue,callback) {
    $("#" + objControl).empty();
    $("#" + objControl).append("<option value=\"\">--选择品牌--</option>");
    if (categoryId == "") {
        return;
    }
    var url = AjaxServerUrl + "?action=GetBrandsByCategory&CategoryID=" + categoryId;
    $.ajax(
    {
        type: "Get",
        url: url,
        dataType: "json",
        success: function (data) {
            var options = "";
            if (data != null) {
                var isHave = false;
                for (var i = 0; i < data.length; ++i) {
                    if (defaultValue == data[i]._id) {
                        options += "<option value=\"" + data[i]._id + "\" Selected>" + data[i]._name + "</option>";
                        isHave = true;
                    }
                    else
                        options += "<option value=\"" + data[i]._id + "\">" + data[i]._name + "</option>";
                }
            }
            else {
                $("#" + objControl).empty();
                options += "<option value=\"\">--无品牌信息--</option>";
            }
            $("#" + objControl).append(options);

            if (!isHave && callback != null)
                callback();

        }
    });
}



function AddOnSale() {
    $("#" + OnSalesTableRow).show();
   
    var tr = oo(OnSalesTable).insertRow(oo(OnSalesTable).rows.length);
    td = tr.insertCell(0);
    td.innerHTML = ((CurRowOfOnSales + 1) + ".");  //序号列；
    td.align = "center";
   
    td = tr.insertCell(1);
    td.innerHTML = "包装规格：";
    td.align = "right";

    td = tr.insertCell(2);
    //td.innerHTML = "<input name=\"txtMinQuantityOf" + CurRowOfOnSales + "\" type=\"text\"  class=\"border6\" id=\"txtMinQuantityOf" + CurRowOfOnSales + "\" size=\"5\" />";
    td.innerHTML = "<select id=\"ddlPackUnitOf" + CurRowOfOnSales + "\" name=\"ddlPackUnitOf" + CurRowOfOnSales + "\">" + SelectOptionOfPackUnit + "</Select>";
    td.align = "left";

    td = tr.insertCell(3);
    td.innerHTML = "单价：";
    td.align = "right";

    td = tr.insertCell(4);
    td.innerHTML = "<input name=\"txtSalePriceOf" + CurRowOfOnSales + "\" type=\"text\"  class=\"border6\" id=\"txtSalePriceOf" + CurRowOfOnSales + "\" size=\"5\" />";
    td.align = "left";

    td = tr.insertCell(5);
    td.innerHTML = "[ <a href=\"javascript:void(0);\" onclick=\"javascript:DeleteOnSale(this);\" >删除</a> ]";
    td.align = "center";
   
    CurRowOfOnSales++;
}

function DeleteOnSale(objRow) {
    if (!confirm("确定要删除该行售卖规格吗?"))
        return false;

    var rowIndex = objRow.parentNode.parentNode.rowIndex;

    oo(OnSalesTable).deleteRow(rowIndex);
    if (oo(OnSalesTable).rows.length == 0) {
        CurRowOfOnSales = 0;
        $("#" + OnSalesTableRow).hide();
    }
}



function AddPriceRule() {
    $("#"+RulesTableRow).show(); 
    var tr = oo(RulesTable).insertRow(oo(RulesTable).rows.length);
    td = tr.insertCell(0);
    td.innerHTML = ((CurRowOfRules + 1) + ".");  //序号列；
    td.align = "center";

    td = tr.insertCell(1);
    td.innerHTML = "起购数量：";  
    td.align = "right";
    
    td = tr.insertCell(2);
    td.innerHTML = "<input name=\"txtMinQuantityOf" + CurRowOfRules + "\" type=\"text\"  class=\"border6\" id=\"txtMinQuantityOf" + CurRowOfRules + "\" size=\"5\" />"; 
    td.align = "left";

    td = tr.insertCell(3);
    td.innerHTML = "单价：";
    td.align = "right";

    td = tr.insertCell(4);
    td.innerHTML = "<input name=\"txtPriceOf" + CurRowOfRules + "\" type=\"text\"  class=\"border6\" id=\"txtPriceOf" + CurRowOfRules + "\" size=\"5\" />";
    td.align = "left";

    td = tr.insertCell(5);
    td.innerHTML = "[ <a href=\"javascript:void(0);\" onclick=\"javascript:DeletePriceRule(this);\" >删除</a> ]"; 
    td.align = "center";

    CurRowOfRules++;
}

function DeletePriceRule(objRow) {
    if (!confirm("确定要删除该行价格规则吗?"))
        return false;

    var rowIndex = objRow.parentNode.parentNode.rowIndex;
   
    oo(RulesTable).deleteRow(rowIndex);
    if (oo(RulesTable).rows.length == 0) {
        CurRowOfRules = 0;
        $("#" + RulesTableRow).hide();
    }
}

function InsertGoodsPic(bianhao) {
    var html = "<img src=\"" + UploadPic[bianhao]._originalpictureurl + "\" > ";
    InsertEditorHTML("txtDescription", html);
}

function DeleteGoodsPic(bianhao) {
    UploadPic.removeEx(bianhao);
    OutGoodsPic();
}
function SetMajor(bianhao) {
    for (var i = 0; i < UploadPic.length; ++i) {
        if (i == bianhao)
            UploadPic[i]._ismajor = true;
        else
            UploadPic[i]._ismajor = false;
    }
}

function OutGoodsPic() {
    if (UploadPic == null || UploadPic.length == 0) {
        $("#trGoodsPic").hide();
        $("#divGoodsPic").html("");
    }
    else {
        $("#trGoodsPic").show();
        var html = new Array();
        html.push("<table  border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >");
        html.push("  <tr>");
        for (var i = 0; i < UploadPic.length; ++i) {
            html.push("    <td><table width=\"100\"  height=\"100\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\">");
            html.push("      <tr>");
            html.push("        <td height=\"80\" style=\"height:80px;\"><a href=\"javascript:void(0);\" ondblclick=\"InsertGoodsPic("+i+");\" title=\"双击插入到编辑框中\"><img src=\"" + UploadPic[i]._smallpictureurl + "\" width=\"100\" height=\"80\"></a></td>");
            html.push("      </tr>");
            html.push("      <tr>");
            html.push("        <td align=\"center\">");

            html.push("		<input type=\"radio\" name=\"rbIsMajor\" value=\"1\" ");
            if (UploadPic[i]._ismajor)
                html.push(" checked ");
            html.push("  onclick=\"SetMajor(" + i + ")\"/>主图 [<a href=\"javascript:void(0);\" onclick=\"DeleteGoodsPic(" + i + ");\"  >删除</a>] </td>");
            html.push("      </tr>");
            html.push("    </table></td>");

        }
        html.push("  </tr>");
        html.push("</table>");
        $("#divGoodsPic").html(html.join(""));
    }

}


///产品图片上传成功后的处理；
function uploadSuccess(file, fileUrl) {
    try {
        var pic = clone(ModelOfGoodsPicture);
        pic._goodsid = GoodsID;
        pic._originalpictureurl = fileUrl;
        pic._middlepictureurl = fileUrl;
        pic._smallpictureurl = fileUrl;
        pic._supersmallpictureurl = fileUrl;
        if (UploadPic.length > 0)
            pic._ismajor = false;
        else
            pic._ismajor = true;
        pic._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
        UploadPic.push(pic);
        OutGoodsPic();
    } catch (ex) {
        this.debug(ex);
    }
}

///获取录入界面的HTML;
function GetHtmlForm() {
    var html = new Array();
    html.push("<form>");
    html.push("<table width=\"700\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\">");
    html.push("  <tr>");
    html.push("    <td colspan=\"4\" class=\"TableHeadRow\">&gt;&gt;商品基本信息</td>");
    html.push("  </tr>");
    
    html.push("  <tr>");
    html.push("    <td align=\"right\">所属类别：</td>");
    html.push("    <td><select name=\"ddlCategory\" id=\"ddlCategory\"  onchange=\"GetBrands(this.options[this.selectedIndex].value,'ddlBrand');\">");
    html.push("      <option value=\"\">---请选择商品分类---</option>");
    html.push(SelectOptionOfCategory);
    html.push("        </select>");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("    <td width=\"80\" align=\"right\">所属品牌：</td>");
    html.push("    <td><select name=\"ddlBrand\" id=\"ddlBrand\">");
    html.push("      <option value=\"\">---请选择品牌---</option>");
    html.push("    </select>");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">商品名称：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtGoodsName\" type=\"text\"  class=\"border6\" id=\"txtGoodsName\" size=\"70\" />");
    html.push("      <span class=\"red\">(*)</span>");

    html.push("&nbsp;&nbsp;<label for=\"chkIsGroup\"><input type=\"checkbox\" name=\"chkIsGroup\" value=\"1\" id=\"chkIsGroup\" />是否为套装</label>");
    html.push("</td>");
    html.push("    </tr>");
    

    html.push("  <tr>");
    html.push("    <td width=\"80\" align=\"right\">商品重量：</td>");
    html.push("    <td width=\"259\"><input name=\"txtWeight\" type=\"text\"  class=\"border6\" id=\"txtWeight\" size=\"10\">");
    html.push("      <span class=\"red\">g(*)</span></td>");
    html.push("    <td width=\"80\" align=\"right\">商品产地：</td>");
    html.push("    <td width=\"281\"><select name=\"ddlGoodsPlace\" id=\"ddlGoodsPlace\">");
    html.push("      <option value=\"\">---请选择产地---</option>");
    html.push(SelectOptionOfPlace);
    html.push("</select>");

    html.push("<select name=\"ddlSpecialArea\" id=\"ddlSpecialArea\">");
    html.push("      <option value=\"\">-所属专区-</option>");
    html.push(SelectOptionOfSpecialArea);
    html.push("</select>");

    html.push("</td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">包装类型：</td>");
    html.push("    <td><select name=\"ddlPackUnit\" id=\"ddlPackUnit\">");
    html.push("      <option value=\"\">---请选择包装类型---</option>");
    html.push(SelectOptionOfPackUnit);
    html.push("        </select>");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("    <td align=\"right\">商品单位：</td>");
    html.push("    <td><select name=\"ddlGoodsUnit\" id=\"ddlGoodsUnit\">");
    html.push("      <option value=\"\">---请选择商品单位---</option>");
    html.push(SelectOptionOfGoodsUnit);
    html.push("    </select></td>");
    html.push("  </tr>");


    html.push("  <tr>");
    html.push("    <td align=\"right\" class=\"red\">市场价：</td>");
    html.push("    <td><input name=\"txtMarketPrice\" type=\"text\"  class=\"border6\" id=\"txtMarketPrice\" size=\"10\" />");
    html.push("      <span class=\"red\" >(*)</span></td>");

    html.push("    <td width=\"80\" align=\"right\">保质期：</td>");
    html.push("    <td ><input name=\"txtShelflifeDays\" type=\"text\"  class=\"border6\" id=\"txtShelflifeDays\" value=\"180\" size=\"5\" />天 <span class=\"red\">(*)</span>");

    html.push("    </tr>");
    html.push("  <tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\" class=\"red\">售价：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtSalePrice\" type=\"text\"  class=\"border6\" id=\"txtSalePrice\" size=\"10\" />");
    html.push("      <span class=\"red\" >(*)</span>[<a href=\"javascript:AddOnSale();\" class=\"green \">添加更多售卖规格</a>] ");
    //html.push("[<a href=\"javascript:AddPriceRule();\" class=\"green \">添加更多价格</a>] ");
    html.push("</td>");

   
    html.push("</td>");
    html.push("  </tr>");

   



    html.push("  <tr id=\"trMoreOnSales\" style=\"display:none;\">");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td colspan=\"3\">");
    html.push("<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\" id=\"tableOfOnSales\">");
    html.push("</table>");
    html.push("</td>");
    html.push("  </tr>");


    html.push("  <tr id=\"trMorePrice\" style=\"display:none;\">");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td colspan=\"3\">");
    html.push("<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\" id=\"tableOfPriceRules\">");
    html.push("</table>");
    html.push("</td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\" class=\"red\">是否抢购：</td>");
    html.push("    <td colspan=\"3\">");
    html.push("    <label><input name=\"chkIsRush\" type=\"checkbox\" id=\"chkIsRush\" />是否抢购</label>  ");
    html.push("   抢购价：<input name=\"txtRushPrice\" type=\"text\"  class=\"border6\" id=\"txtRushPrice\" size=\"10\" value=\"0\" />  ");
    html.push("   抢购限量：<input name=\"txtRushMaxQuantity\" type=\"text\"  class=\"border6\" id=\"txtRushMaxQuantity\" size=\"10\" value=\"0\" /> ");

    html.push("</td>");

    html.push("</td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">商品条码：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtBarcode\" type=\"text\"  class=\"border6\" id=\"txtBarcode\" size=\"40\" /></td>");
    html.push("    </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">促销短语：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtPromotions\" type=\"text\"  class=\"border6\" id=\"txtPromotions\" size=\"80\" /></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">赠送积分：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtGiveScores\" type=\"text\"  class=\"border6\" id=\"txtGiveScores\" value=\"0\" size=\"10\" />");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">包装清单：</td>");
    html.push("    <td colspan=\"3\"><textarea name=\"txtPackage\" cols=\"84\" rows=\"3\" class=\"border6\" id=\"txtPackage\"></textarea></td>");
    html.push("    </tr>");
    html.push("   <tr>");
    html.push("    <td align=\"right\">商品售后：</td>");
    html.push("    <td colspan=\"3\"><textarea name=\"txtAfterService\" cols=\"84\" rows=\"3\" class=\"border6\" id=\"txtAfterService\"></textarea></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">排序值：</td>");
    html.push("    <td colspan=\"3\"><input name=\"txtOrderValue\" type=\"text\" class=\"border6\" id=\"txtOrderValue\" value=\"0\" size=\"5\">");
    html.push("    <span class=\"red\">(*)</span></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">销售状态：</td>");
    html.push("    <td><select name=\"ddlSaleStatus\" id=\"ddlSaleStatus\">");
    html.push(SelectOptionOfSaleStatus);
    html.push("    </select></td>");
    html.push("    <td align=\"right\">商品状态：</td>");
    html.push("    <td><select name=\"ddlStatus\" id=\"ddlStatus\">");
    html.push("      <option value=\"正用\">正用</option>");
    html.push("      <option  value=\"停用\">停用</option>");
    html.push("    </select></td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">商品推荐：</td>");
    html.push("    <td colspan=\"3\">" + CheckOptionOfCommend + "</td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">最佳组合：</td>");
    html.push("    <td colspan=\"3\"><input name=\"btnSelGoods\" type=\"button\" id=\"btnSelGoods\" value=\" 设置组合 \" class=\"btn2\" ><span id=\"spPacks\"></span></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">商品图片：</td>");
    html.push("    <td colspan=\"3\"><span id=\"spUploadBtn\"></span>(*)</td>");
    html.push("    </tr>");

    html.push("  <tr id=\"trGoodsPic\" style=\"display:none;\">");
    html.push("    <td align=\"right\"></td>");
    html.push("    <td colspan=\"3\"><div  style=\"width:610px;overflow-y:hidden;overflow-x:auto; height:130px;\" id=\"divGoodsPic\">");
   
    html.push("</div></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">商品介绍：</td>");
    html.push("    <td colspan=\"3\"><textarea name=\"txtDescription\" cols=\"60\" rows=\"4\" class=\"border6\" id=\"txtDescription\"></textarea></td>");
    html.push("    </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td colspan=\"3\"><input name=\"btnSave\" type=\"button\" id=\"btnSave\" value=\" 保 存 \" class=\"btn2\" onclick=\"Save();\">");
    html.push("   &nbsp;<input name=\"btnSave\" type=\"button\" id=\"btnSave\" value=\" 保存为新商品 \" class=\"btn2\" onclick=\"Save(true);\">");
    html.push("    <input name=\"btnReset\" type=\"reset\" id=\"btnReset\" value=\" 重 置 \" class=\"btn2\">");
    html.push("    <input name=\"btnClose\" type=\"button\" id=\"btnClose\" value=\"关闭本窗口\" class=\"btn2\" onclick=\"yesOther(false);\"></td>");
    html.push("    </tr>");
    html.push("</table>");
    html.push("</form>");
    return html.join("");
}



function yesOther(t) {
    if (SWFUploader != null) {
        SWFUploader.destroy();
    }
    var IsHavePopDiv = false;
    var lastDivName = "";
    var divs = document.getElementsByTagName("DIV");
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].id.indexOf(prePopDivName) >= 0) {
            fullPopDivName = divs[i].id;
        }
    }
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].id.indexOf(prePopDivName) >= 0 && divs[i].id != fullPopDivName) {
            oo(divs[i].id).style.display = "";
            IsHavePopDiv = true;
        }
    }
    if (!t) {
        var bgObj2 = document.getElementById(fullPopDivName);
        document.body.removeChild(bgObj2);
        if (!IsHavePopDiv) {
            var bgObj = document.getElementById("bgDiv");
            document.body.removeChild(bgObj);
        }
    }
    else {
        var bgObj2 = document.getElementById(fullPopDivName);
        document.body.removeChild(bgObj2);
        if (!IsHavePopDiv) {
            var bgObj = document.getElementById("bgDiv");
            document.body.removeChild(bgObj);
        }
    }
    for (var i = 0; i < divs.length; i++) {
        if (divs[i].id.indexOf(prePopDivName) >= 0) {
            fullPopDivName = divs[i].id;
        }
    }
}










